package com.daykw.douyin.service;

import java.util.List;

import javax.annotation.Resource;

import org.nutz.dao.Cnd;
import org.nutz.dao.impl.NutDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.daykw.douyin.model.VideoAuth;
import com.daykw.douyin.model.VideoComment;
import com.daykw.douyin.model.VideoInfo;

@Service
public class ApiService {
	Logger logger = LoggerFactory.getLogger(getClass());
	@Resource
	private NutDao dao;

	public List<VideoAuth> getApiUserDate(int limit) {
		// JSONObject ret = new JSONObject();

		List<VideoAuth> auths = dao.query(VideoAuth.class, Cnd.where("status", "=", 2));

		for (VideoAuth auth : auths) {
			List<VideoInfo> videos = dao.query(VideoInfo.class, Cnd.where("dataid", "=", auth.getDataid()));

			for (VideoInfo v : videos) {
				List<VideoComment> comments = dao.query(VideoComment.class, Cnd.where("kw_id", "=", v.getKw_id()));

				v.setComments(comments);
			}

			auth.setVideos(videos);
		}
		return auths;

	}
}
